﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;

namespace SIGEB.Modelo
{
    public class String1
    {
        public static bool soloNumeros(string a)
        {
            try
            {
                long.Parse(a);
            }
            catch (FormatException)
            {
                return false;
            }
            return true;
        }

        public static bool sinCaracteres(string a, string restricciones)
        {
            a = a.ToUpper();
            restricciones = restricciones.ToUpper();
            foreach (char act in a)
            {
                foreach (char act2 in restricciones)
                {
                    if (act == act2)
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        public static string RemoveAccentsWithNormalization(string inputString)
        {
            string normalizedString = inputString.Normalize(NormalizationForm.FormD);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < normalizedString.Length; i++)
            {
                UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(normalizedString[i]);
                if (uc != UnicodeCategory.NonSpacingMark)
                {
                    sb.Append(normalizedString[i]);
                }
            }

            return (sb.ToString().Normalize(NormalizationForm.FormC));
        }

        public static bool contiene(string a, string b)
        {
            if (String.IsNullOrEmpty(b))
            {
                return false;
            }
            string cadena1 = RemoveAccentsWithNormalization(a.ToUpper());
            string cadena2 = RemoveAccentsWithNormalization(b.ToUpper());
            return cadena1.Contains(cadena2);
        }

        public static bool soloLetras(string a)
        {
            a = a.ToUpper();
            foreach (char act in a)
            {
                if (!esLetra(act))
                {
                    return false;
                }
            }
            return true;
        }

        private static bool esLetra(char a)
        {
            foreach (char act in letras)
            {
                if (act == a)
                {
                    return true;
                }
            }
            return false;
        }

        private static string letras
        {
            get
            {
                return "AÁÄBCDEÉËFGHIÍÏJKLMNÑOÓÖPQRSTUÚÜVWXYZ";
            }
        }
    }
}
